package com.cn.common.core.model.websocket;

import com.cn.common.core.model.Result;
import com.cn.common.core.model.ResultCode;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/5/15 13:46
 * @Modified By:
 */


public class HttpResult<T extends Object> {
    /**
     * 结果码
     */
    private int resultCode;

    /**
     * 封装结果内容，返回结果内容
     */
    private T content;
    public static <T extends Object> HttpResult<T> SUCCESS(T content){
        HttpResult<T> result = new HttpResult<T>();
        result.resultCode = ResultCode.SUCCESS;
        result.content = content;
        return result;
    }

    /**
     * 封装结果内容，返回成功结果，
     * @param <T>
     * @return
     */
    public static <T extends Object> HttpResult<T> SUCCESS(){
        HttpResult<T> result = new HttpResult<T>();
        result.resultCode = ResultCode.SUCCESS;
        return result;
    }

    public static <T extends Object> HttpResult<T> ERROR(int resultCode){
        HttpResult<T> result = new HttpResult<T>();
        result.resultCode = resultCode;
        return result;
    }

    public static <T extends Object> HttpResult<T> valueOf(int resultCode, T content){
        HttpResult<T> result = new HttpResult<T>();
        result.resultCode = resultCode;
        result.content = content;
        return result;
    }


    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public boolean isSuccess(){
        return this.resultCode == ResultCode.SUCCESS;
    }
}
